clearvars -except b 
load datafromstata M pxest


tvals2 = [5 9];
bvals2 = [.9 1];
testt2 = zeros(2,M);
for i=1:2
    beta = .95;
    T = tvals2(i);
    testt2(i,:) = gammafunc(T,beta, M, pxest);
end

testb2 = zeros(2,M);
for i=1:2
    beta = bvals2(i);
    T = 7;
    testb2(i,:) = gammafunc(T,beta, M, pxest);
end

gammarob = [testt2; testb2]';

load est_res_s2 rentd M con_m 
load datafromstata gamma 

statmwtp = rentd;

picmwtp = 0*rentd;
picmwtpr1 = 0*rentd; picmwtpr2 = 0*rentd; picmwtpr3 = 0*rentd; picmwtpr4 = 0*rentd;
for m = 1:M
    index = find(con_m==m);
    picmwtp(index) = statmwtp(index)/gamma(m);
    picmwtpr1(index) = statmwtp(index)/gammarob(m,1);
    picmwtpr2(index) = statmwtp(index)/gammarob(m,2);
    picmwtpr3(index) = statmwtp(index)/gammarob(m,3);
    picmwtpr4(index) = statmwtp(index)/gammarob(m,4);
end


for m = 1:M
    index = find(con_m==m);
    res2(m,:) = [mean(picmwtp(index)) mean(picmwtpr1(index)) mean(picmwtpr2(index)) mean(picmwtpr3(index)) mean(picmwtpr4(index)) ];
 end

rob_Tb = res2(:,2:5);
rob_base = res2(:,1);
save rob_Tb rob_Tb rob_base
